package com.hunt.service.impl;

import com.hunt.dao.AppVideoMapper;
import com.hunt.model.entity.LecturerArticle;
import com.hunt.model.entity.LecturerVideo;
import com.hunt.service.LecturerZoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import java.util.List;


@Repository
@Service
public class LecturerZoneServiceImpl implements LecturerZoneService {


 @Autowired
 private MongoTemplate mongoTemplate;

 @Autowired
 private AppVideoMapper appVideoMapper;

    @Override
    public List<LecturerVideo> getLecturerVideoByPositionSize(Integer position, Integer size,String type) {
        return appVideoMapper.findAppVideo(position,size,type);
    }

    @Override
    public void getVideoDetailFromWeChat(Integer type) {

    }

    @Override
    public List<LecturerArticle> findLecturerArticleByPositionSize(int position, int size) {

        //用来封装所有条件的对象
        Query query = new Query();
        query.with(new Sort(Sort.Direction.DESC,"releaseDate"));//发布日期排序
        query.skip(position).limit(size);//分页操作

        return mongoTemplate.find(query, LecturerArticle.class);
    }

    @Override
    public LecturerArticle findArticleDetailById(String id) {
        Query query = new Query();
        Query criteria = query.addCriteria(Criteria.where("_id").is(id));
        return mongoTemplate.findOne(criteria, LecturerArticle.class);
    }



}
